package com.slz3.business.module.socialManagement.socShow.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.socialManagement.socShow.domain.SocShow;
import com.slz3.business.module.socialManagement.socShow.domain.SocShowFactory;
import com.slz3.business.module.socialManagement.socShow.steward.SocShowSpecification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.util.*;

@Slf4j
@Service
public class SocShowServiceImpl implements SocShowService {

    @Override
    public SocShow save(SocShow socShow) {
        return Repositorys.socShow.save(SocShowFactory.initBaseFields(socShow));
    }

    @Override
    public Page<SocShow> page(MultiValueMap<String, String> params) {
        Page<SocShow> socShowPage = Repositorys.socShow.findAll(
                SocShowSpecification.findJoin(params), PageableSteward.extract(params)
        );
        return socShowPage;
    }

    @Override
    public SocShow modify(SocShow socShowNew) {
        return Repositorys.socShow.saveAndFlush(SocShowFactory.initBaseFields(socShowNew));
    }

    @Override
    public Optional<SocShow> single(UUID uuid) {
        return Repositorys.socShow.findById(uuid);
    }

    @Override
    public List<SocShow> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.socShow.findAllById(uuids);
    }

    @Override
    public List<SocShow> delete(List<SocShow> socShowList) {
        socShowList.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            SocShowFactory.initBaseFields(item);
        });
        return Services.socShowTransactional.batchModify(socShowList);
    }

}
